package com.robot.command;

import iqq.im.actor.QQActor;
import iqq.im.bean.QQGroupMember;
import iqq.im.bean.QQMsg;
import iqq.im.bean.content.FontItem;
import iqq.im.bean.content.TextItem;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.robot.core.Context;

public abstract class CommandAcotr implements QQActor{
	protected QQMsg msg;
	protected Context context;
	protected String param;
	protected String param1;
	protected String param2;
	protected String param3;
	public CommandAcotr(Context context,QQMsg msg) {
		this.context = context;
		this.msg = msg;
		param = msg.getText().trim();
		Pattern	pattern = Pattern.compile("[#＃]([a-zA-Z?？]{1,4}) *([^ ]*) ?([^ ]*) ?([^ ]*)");
		Matcher	matcher = pattern.matcher(msg.getText());
		if(matcher.find()){
			if(matcher.group(2)==null||"".equals(matcher.group(2))){
				setParam1(msg.getFrom().getQQ()+"");
			}else{
				setParam1(matcher.group(2));
				setParam2(matcher.group(3));
				setParam3(matcher.group(4));
			}
			
		}
	}

	public void replyQQMsg(String replyMsg) {
		QQMsg sendMsg = new QQMsg();
		sendMsg.setType(msg.getType());
		if (replyMsg.length() > 300 || msg.getType() == QQMsg.Type.SESSION_MSG) {
			sendMsg.setTo(msg.getFrom());
			sendMsg.setType(QQMsg.Type.SESSION_MSG);
		} else if (msg.getType() == QQMsg.Type.GROUP_MSG) {
			if (msg.getFrom() instanceof QQGroupMember)
				sendMsg.setGroup(msg.getGroup());
		}
		sendMsg.addContentItem(new TextItem(replyMsg));
		sendMsg.addContentItem(new FontItem());
		context.replyMsg(sendMsg);
	}
	public String getParam1() {
		return param1;
	}
	public void setParam1(String param1) {
		this.param1 = param1;
	}
	public String getParam2() {
		return param2;
	}
	public void setParam2(String param2) {
		this.param2 = param2;
	}
	public String getParam3() {
		return param3;
	}
	public void setParam3(String param3) {
		this.param3 = param3;
	}

	public QQMsg getMsg() {
		return msg;
	}
	public void setMsg(QQMsg msg) {
		this.msg = msg;
	}

	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}
	
}